package map_set.leetcode.easy;

/**
 * @author bruin_du
 * @description 有效的变位词
 * @date 2022/8/12 20:20
 **/
public class OfferII032_IsAnagram {
    // 用HashMap也可以实现
    public boolean isAnagram(String s, String t) {
        int lenS = s.length(), lenT = t.length();
        if (lenS != lenT || s.equals(t)) return false;
        int[] arr = new int[26];
        char[] strS = s.toCharArray(), strT = t.toCharArray();
        for (int i = 0; i < lenS; i++) {
            arr[strS[i] - 'a']++;
            arr[strT[i] - 'a']--;
        }
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] != 0) return false;
        }
        return true;
    }
}
